<template>
    <div class="close-project">
        <pui-dialog :maskClick="false" :title="props.title" v-model="componentRef.dialogVisible" :animate="props.animate" @onSubmit="closeDialog">
            <template #content>
                <div>是否确定关闭当前项目？</div>
            </template>
        </pui-dialog>
    </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
    name: 'CloseProject'
})
</script>
<script lang="ts" setup>
import { reactive } from 'vue'
import { projectService as project } from '@/services/phot_client/client'
const emit = defineEmits({
    'closeProject': (val: any) => {}
})
const props = defineProps({
    title: {
        type: String,
        default: '关闭项目'
    },
    animate: {
        type: String,
        default: 'fade'
    },
    directoryPath: {
        type: String,
        default: ''
    },
    fileName: {
        type: String,
        default: ''
    },
    projectName: {
        type: String,
        default: ''
    }
})
const componentRef = reactive({
    dialogVisible: false
})
const init = () => {
    componentRef.dialogVisible = true
}
const closeDialog = () => {
    emit('closeProject', 'closeProject')
    componentRef.dialogVisible = false
}
const closeProject = async () => {
    await project.closeProject(props.projectName, '').then((res: any) => {
        console.log(res)
        saveFile()
    }).catch((err: any) => {
        console.log(err)
    })
}
const saveFile = async () => {
    const fileObj = {
        path: props.directoryPath,
        name: props.fileName,
        type: 6,
        data: ``
    }
    await project.saveFile(props.directoryPath, fileObj).then((res: any) => {
        console.log(res)
    }).catch((err: any) => {
        console.log(err)
    })
}
defineExpose({
    init,
    closeDialog
})
</script>